
function jsonSecurity (url) {
  url = url.replace(/\\/g, "@@"); //反斜杠转换为@@
  url = url.replace(/\$/g, "--"); //$符转换为--
  url = url.replace(/\|/g, "^^"); //竖杠转换为^^
  url = url.replace(/%/g, "!!");  //%转换为!!
  url = url.replace(/\"/g, "=="); //双引号转换为==
  url = url.replace(/\'/g, "**"); //单引号转换为**
  return url;
};

const http = axios.create({
  timeout: 5000, // 请求超时时间
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  transformRequest: [function (data) {
    let ret = ''
    for (let it in data) {
      if (typeof data[it] === 'string') {
        ret += encodeURIComponent(it) + '=' + jsonSecurity(data[it]) + '&'
      } else {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
    }
    return ret
  }],
});
http.interceptors.response.use(response => {
  return response.data;
});

function getBase64 (file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
  });
}
const { locales } = window.antd;

/** 表格数据列配置 */
const tableColumns = [
  {
    title: 'id',
    dataIndex: 'id',
    align: 'center',
    width: 80,
  },
  {
    title: '盲盒活动号',
    dataIndex: 'orderNo',
    align: 'center',
    // width: 120,
  },
  {
    title: '盲盒订单状态',
    dataIndex: 'orderNo',
    align: 'center',
    // width: 120,
  },
  {
    title: '商品主标题',
    dataIndex: 'commodityMainTitle',
    align: 'center',
    // width: 150,
  },
  {
    title: '商品属性值',
    dataIndex: 'updatedAt',
    align: 'center',
    // width: 100,
  },
  {
    title: '商品订单状态',
    dataIndex: 'updatedAt',
    align: 'center',
    // width: 100,
  },
  {
    title: '渠道',
    dataIndex: 'updatedAt',
    align: 'center',
    // width: 100,
  },
  {
    title: '支付金额',
    dataIndex: 'updatedAt',
    align: 'center',
    // width: 100,
  },
  {
    title: '支付时间',
    dataIndex: 'updatedBy',
    align: 'center',
    // width: 100,
  },
  {
    title: '操作',
    align: 'center',
    dataIndex: 'action',
    fixed: 'right',
    width: 200,
    scopedSlots: { customRender: 'action' },
  }
]
// 商品属性
const goodsAttrColumn = [
  {
    title: '商品图片',
    dataIndex: 'orderNo',
    align: 'center',
  },
  {
    title: '商品',
    dataIndex: 'orderNo',
    align: 'center',
  },
  {
    title: '商品编码',
    dataIndex: 'orderNo',
    align: 'center',
  },
  {
    title: '商品属性值',
    dataIndex: 'orderNo',
    align: 'center',
  },
  {
    title: '供货价',
    dataIndex: 'orderNo',
    align: 'center',
  },
  {
    title: '售价',
    dataIndex: 'orderNo',
    align: 'center',
  },
  {
    title: '到手价',
    dataIndex: 'orderNo',
    align: 'center',
  },
  {
    title: '活动价',
    dataIndex: 'orderNo',
    align: 'center',
  },
  
  {
    title: '数量',
    dataIndex: 'orderNo',
    align: 'center',
  },
  {
    title: '运费',
    dataIndex: 'orderNo',
    align: 'center',
  },
  
  

]
moment.locale('zh-cn');
var vm = new Vue({
  el: '#app',
  data: {
    locales,
    /** 展示 table 页面 */
    showTablePage: true,/** 搜索栏样式配置 */
    layout: {
      labelCol: { span: 7 },
      wrapperCol: { span: 17 },
    },
    /** 搜索栏数据 */
    searchForm: {},
    /** 表格数据 */
    tableData: [],
    /** 表格分页数据查询中标识位 */
    loading: false,
    /** 分页器 */
    pagination: {
      showSizeChanger: true,
      showQuickJumper: true,
      total: null,
      pageSize: 10,
      current: 1,
      showTotal: (total, range) => `共${total}条`,
      pageSizeOptions: ['10', '25', '50', '100'],
      buildOptionText: (size) => {
        return `${size.value}条/页`
      }
    },

    tableScroll: { x: 1000, y: 400 },
    dialogGoodsInfoTemplate: {
      // 商品编码
      dialogformname0: '',
      attrs: [{
        // 属性
        attrs0: '',
        mhspNum: 1,
      }, {
        // 属性
        attrs0: '',
        mhspNum: 13,
      },]
    },
    dialogForm: {
      dialogformname0:'',
      dialogGoodsInfo: [],
      attrs: [{
        // 属性
        attrs0: '',
        mhspNum: 1,
      }, {
        // 属性
        attrs0: '',
        mhspNum: 13,
      },]
    },
    dialogFormDisable: false,
    dialogFormRules: {
      dialogformname0: [{ required: true, message: 'Please input your username!' }]
    }
  },
  methods: {
    // 添加商品
    onAddGoodsForm (formIndex) {
      this.dialogForm.dialogGoodsInfo.splice(formIndex+1,0,JSON.parse(JSON.stringify(this.dialogGoodsInfoTemplate)))
      this.$message.success('添加成功');
    },
    // 删除商品
    onDelGoodsForm (formIndex) {
      const _this = this
      this.$confirm({
        title: '删除',
        content: '确认删除？',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk () {
          console.log('OK');
          _this.dialogForm.dialogGoodsInfo.splice(formIndex, 1)　
          _this.$message.success('删除成功');
        },
        onCancel () {
          console.log('Cancel');
        },
      });
    },
    // 删除表单中商品属性
    removeAttrs (record, index, formIndex) {
      console.log("removeAttrs", { record, index, formIndex })
      const _this = this
      this.$confirm({
        title: '删除',
        content: '确认删除？',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk () {
          console.log('OK');
          _this.dialogForm.dialogGoodsInfo[formIndex].attrs.splice(index, 1)
        },
        onCancel () {
          console.log('Cancel');
        },
      });
    },
    // add  update
    onSetShowTablePage (value) {
      this.showTablePage = false
      if(value == 'add')
        this.dialogForm.dialogGoodsInfo = [JSON.parse(JSON.stringify(this.dialogGoodsInfoTemplate))]
    },
    onSubmit(type) {
      console.log("onSubmit")
      this.showTablePage = true

    },
    async queryTableData () {
      
    },
    /** 分页器事件处理 */
    handleTableChange (pagination) {
      // 设置分页器数据
      this.$set(this, 'pagination', pagination);
      // 查询 table 数据
      this.queryTableData();
    },
    /** 弹窗按钮点击处理 */
    async dialogButtonClick (auditStatus) {
      if (auditStatus === 'CANCEL') {
        this.showTablePage = true;
        setTimeout(() => {
          window.scrollTo(0, 0);
        }, 400);
        return;
      }
    },
    /** 重置搜索查询条件 */
    resetSearchFormInfo () {
      this.searchForm = {};
      this.$refs.searchFormCategoryCascader.value = [];
      console.log('重置搜索查询条件');
    },
  },
  computed: {
  },
  async created () {
    this.dialogForm.dialogGoodsInfo = [JSON.parse(JSON.stringify(this.dialogGoodsInfoTemplate))]
  },
});